package com.base.cn.platform.os.controller.manage.config;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.constants.ConfigName;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.entity.manage.config.SysConfig;
import com.base.cn.platform.os.service.manage.config.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

/**
 * 后台配置管理
 *
 * @author s.li
 * @create 2018-04-09-19:08
 */
@Controller
@RequestMapping("/admin/manage/config")
public class AdminSysConfigController extends AdminBaseController {

    @Autowired
    private SysConfigService sysConfigService;


    /**
     * 显示配置详情
     * @param id 配置ID
     * @return 详情页面
     */
    @RequestMapping("/showConfigInfo")
    public String showConfigInfo(Model model,
                                 @RequestParam("id") BigDecimal id){
        SysConfig sysConfig = sysConfigService.getSysConfigById(id);
        model.addAttribute("sysConfig",sysConfig);
        return resultPage("/manage/config/show-config-info");
    }

    /**
     * 初始化列表页面
     * @return
     */
    @RequestMapping("/configList")
    public String configList(Model model,
                             @RequestParam(value = "funType",required = false,defaultValue = "1") int funType){
        model.addAttribute("funType",funType);
        return resultPage("/manage/config/config-list");
    }

    /**
     * 加载数据列表
     * @param model Model
     * @return 列表页面
     */
    @RequestMapping("/ajaxConfigList")
    public String ajaxConfigList(Model model){
        SysConfig params = new SysConfig();
        List<SysConfig> configList = sysConfigService.querySysConfigList(params);
        if(ObjectUtils.isNotEmpty(configList)){
            Map<Integer,List<SysConfig>> configMap = configList.stream().collect(Collectors.groupingBy(e->e.getFunType()));
            model.addAttribute("sysConfigList1",configMap.get(1));
            model.addAttribute("sysConfigList2",configMap.get(2));
            model.addAttribute("sysConfigList3",configMap.get(3));
        }
        return resultPage("/manage/config/ajax-config-list");
    }

    /**
     * 初始化修改页面
     * @param model Model
     * @param id 配置ID
     * @return 操作页面
     */
    @RequestMapping("/initUpdateConfig")
    public String initUpdateConfig(Model model,
                                   @RequestParam("id")BigDecimal id){
        SysConfig sysConfig = sysConfigService.getSysConfigById(id);
        model.addAttribute("sysConfig",sysConfig);
        return resultPage("/manage/config/update-config");
    }

    /**
     * 保存配置数据
     * @return Map<String,Object>
     */
    @RequestMapping("/saveConfig")
    @ResponseBody
    public Map<String,Object> saveConfig(@RequestBody Map<String,Object> params){
        String configType = (String)params.get("configType");
        String context;
        if (configType.trim().equals(ConfigName.SALE)) {
            context = this.getSaleContext(params);
        } else if (configType.trim().equals(ConfigName.LOGO)) {
            context = this.getLogoContext(params);
        } else if (configType.trim().equals(ConfigName.ICO)) {
            context = this.getIcoContext(params);
        } else if (configType.trim().equals(ConfigName.INFO)) {
            context = this.getInfoContext(params);
        } else if (configType.trim().equals(ConfigName.ONOFF)) {
            context = this.getOnOffContext(params);
        } else if (configType.trim().equals(ConfigName.SMS)) {//短信配置
            context = this.getSmsContext(params);
        } else if (configType.trim().equals(ConfigName.EMAIL)) {
            context = this.getEmailContext(params);
        } else if (configType.trim().equals(ConfigName.APP)) {
            context = this.getAppContext(params);
        } else if (configType.trim().equals(ConfigName.APPDOW)) {
            context = this.getAppDowContext(params);
        } else if (configType.trim().equals(ConfigName.H5AMOBILE)) {
            context = this.getAppDowContext(params);
        } else if (configType.trim().equals(ConfigName.SMALLAPP)) {
            context = this.getAppDowContext(params);
        } else if(configType.trim().equals(ConfigName.V96K)){
            context = this.getV96KContext(params);
        } else if (configType.trim().equals(ConfigName.SERVICE)) {
            context = this.getServiceContext(params);
        } else if (configType.trim().equals(ConfigName.PAY)) {
            context = this.getPayContext(params);
        } else if (configType.trim().equals(ConfigName.FREIGHT)) {
            context = this.getFreightContext(params);
        } else if (configType.trim().equals(ConfigName.ATTENT)) {
            context = this.getAttentContext(params);
        } else if (configType.trim().equals(ConfigName.COUNTCODE)) {
            context = this.getCountCodeContext(params);
        } else if (configType.trim().equals(ConfigName.WEIXINAPP)) {
            context = this.getWeiXinContext(params);
        } else if (configType.trim().equals(ConfigName.QQLOGIN)) {
            context = this.getQQLoginContext(params);
        } else if (configType.trim().equals(ConfigName.WXLOGIN)) {
            context = this.getWXLoginContext(params);
        } else if(configType.trim().equals(ConfigName.VERSION)){
            context = this.getVersionContext(params);
        } else if(configType.trim().equals(ConfigName.VLASPROVIDER)){
            context = this.getVLASProviderContext(params);
        }else if(configType.trim().equals(ConfigName.COURSESERVICE)){
            context = this.getServiceCourseContent(params);
        }else if(configType.trim().equals(ConfigName.QAREFUND)){
            context = this.getQaRefund(params);
        }
        else if(configType.trim().equals(ConfigName.LIVETIME)){
            context = this.getLiveTimeContent(params);
        }
        else if(configType.trim().equals(ConfigName.INITID)){
            context = this.getInitIdContent(params);
        }
        else if(configType.trim().equals(ConfigName.WECHATSERVICE)){
            context = this.getWechatServiceContent(params);
        }
        else {
            context = this.configContextToJsonStr(params);
        }
        params.put("context",context);
        SysConfig sysConfig = gson.fromJson(gson.toJson(params),SysConfig.class);
        return sysConfigService.saveConfig(sysConfig);
    }

    /**
     * 获取领先售卖方式Context
     *
     * @param params
     * @return 配置内容
     */
    private String getSaleContext(Map<String,Object> params) {
        String selaSwitch = (String)params.get("selaSwitch");
        Map<String, String> selaSwitchMap = new HashMap<>();
        selaSwitchMap.put("selaSwitch", selaSwitch);
        return gson.toJson(selaSwitchMap);
    }

    /**
     * 获取ico
     *
     * @param params
     * @return 配置内容
     */
    private String getIcoContext(Map<String,Object> params) {
        return getLogoContext(params);
    }

    /**
     * 获取Logo
     *
     * @param params
     * @return 配置内容
     */
    private String getLogoContext(Map<String,Object> params) {
        String url = (String)params.get("url");
        String urlSecond = (String)params.get("urlSecond");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("url", url);
        treeMap.put("urlSecond", urlSecond);
        return gson.toJson(treeMap);
    }

    /**
     * 获取App更新配置内容
     *
     * @param params Map<String,String>
     * @return App更新配置内容
     */
    private String getAppContext(Map<String,Object> params) {
        String anUrl = (String)params.get("anUrl");
        String anVersion = (String)params.get("anVersion");
        String anDepict = (String)params.get("anDepict");
        String iosUrl = (String)params.get("iosUrl");
        String iosVersion = (String)params.get("iosVersion");
        String iosDepict = (String)params.get("iosDepict");
        String anUrlRadio = (String)params.get("anUrlRadio");
        String isMust = (String)params.get("isMust");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("anUrl", anUrl);
        treeMap.put("anVersion", anVersion);
        treeMap.put("anDepict", anDepict);
        treeMap.put("isMust", isMust);
        treeMap.put("iosUrl", iosUrl);
        treeMap.put("iosVersion", iosVersion);
        treeMap.put("iosDepict", iosDepict);
        treeMap.put("anUrlRadio", anUrlRadio);
        return gson.toJson(treeMap);
    }

    /**
     * 获取App二维码图片配置内容
     *
     * @param params Map<String,String>
     * @return App二维码图片配置内容
     */
    private String getAppDowContext(Map<String,Object> params) {
        String url = (String)params.get("url");
        String appHref = (String)params.get("appHref");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("url", url);
        treeMap.put("appHref", appHref);
        return gson.toJson(treeMap);
    }

    /**
     * 获取96K配置信息
     * @param params
     * @return
     */
    private String getV96KContext(Map<String,Object> params){
        String concurrentLive = (String)params.get("concurrentLive");
        String personTimeLive = (String)params.get("personTimeLive");
        String interactiveLive = (String)params.get("interactiveLive");
        String userMobile = (String)params.get("userMobile");
        String c_auth_id = (String)params.get("c_auth_id");
        String c_auth_key = (String)params.get("c_auth_key");
        String p_auth_id = (String)params.get("p_auth_id");
        String p_auth_key = (String)params.get("p_auth_key");
        String i_auth_id = (String)params.get("i_auth_id");
        String i_auth_key = (String)params.get("i_auth_key");
        String customerKey = (String)params.get("customerKey");
        String createLiveUrl = (String)params.get("createLiveUrl");
        String serviceUrl = (String)params.get("serviceUrl");
        String serviceUseInfoUrl = (String)params.get("serviceUseInfoUrl");
        String createVideoUrl = (String)params.get("createVideoUrl");
        String batchCreateVideoUrl = (String)params.get("batchCreateVideoUrl");
        String playback = (String)params.get("playback");
        String deleteVideo = (String)params.get("deleteVideo");
        String close = (String)params.get("close");
        String player = (String)params.get("player");
        String demand = (String)params.get("demand");
        String live = (String)params.get("live");
        String client = (String)params.get("client");
        String browser = (String)params.get("browser");

        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("customerKey", customerKey);
        treeMap.put("createLiveUrl", createLiveUrl);
        treeMap.put("serviceUrl", serviceUrl);
        treeMap.put("serviceUseInfoUrl", serviceUseInfoUrl);
        treeMap.put("createVideoUrl", createVideoUrl);
        treeMap.put("batchCreateVideoUrl", batchCreateVideoUrl);
        treeMap.put("playback", playback);
        treeMap.put("deleteVideo", deleteVideo);
        treeMap.put("close", close);
        treeMap.put("player", player);
        treeMap.put("demand", demand);
        treeMap.put("live", live);
        treeMap.put("client", client);
        treeMap.put("browser", browser);

        treeMap.put("concurrentLive", concurrentLive);
        treeMap.put("personTimeLive", personTimeLive);
        treeMap.put("interactiveLive", interactiveLive);
        treeMap.put("c_auth_id", c_auth_id);
        treeMap.put("c_auth_key", c_auth_key);
        treeMap.put("p_auth_id", p_auth_id);
        treeMap.put("p_auth_key", p_auth_key);
        treeMap.put("i_auth_id", i_auth_id);
        treeMap.put("i_auth_key", i_auth_key);
        treeMap.put("userMobile", userMobile);
        return gson.toJson(treeMap);
    }

    /**
     * 获取客服链接配置
     *
     * @param params Map<String,String>
     * @return 取客服链接配置内容
     */
    private String getServiceContext(Map<String, Object> params) {
        String context = (String) params.get("context");
        String type = (String) params.get("type");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("context", context);
        treeMap.put("type", type);
        return gson.toJson(treeMap);
    }

    /**
     * 获取支付配置
     * @param params
     * @return 支付配置内容
     */
    public String getPayContext(Map<String,Object> params){
        TreeMap<String, String> treeMap = new TreeMap<>();
        //支付宝支付配置
        String alipayStatus = (String)params.get("alipayStatus");
        if(StringUtils.isEmpty(alipayStatus)){
            alipayStatus = "off";
        }
        treeMap.put("alipayStatus", alipayStatus);
        treeMap.put("alipaypartnerID", (String)params.get("alipaypartnerID"));
        treeMap.put("alipayKey", (String)params.get("alipayKey"));
        treeMap.put("sellerEmail", (String)params.get("sellerEmail"));
        treeMap.put("publicKey", (String)params.get("publicKey"));
        treeMap.put("privateKey", (String)params.get("privateKey"));
        //微信支付配置
        String weixinStatus = (String)params.get("weixinStatus");
        if(StringUtils.isEmpty(weixinStatus)){
            weixinStatus = "off";
        }
        treeMap.put("weixinStatus", weixinStatus);
        treeMap.put("appid", (String)params.get("appid"));
        treeMap.put("mch_id", (String)params.get("mch_id"));
        treeMap.put("appSecret", (String)params.get("appSecret"));
        treeMap.put("payKey", (String)params.get("payKey"));
        treeMap.put("openMchId", (String)params.get("openMchId"));
        treeMap.put("openAppAppId", (String)params.get("openAppAppId"));
        treeMap.put("openPayKey", (String)params.get("openPayKey"));
        treeMap.put("applyAppId", (String)params.get("applyAppId"));
        treeMap.put("applyAppSecret", (String)params.get("applyAppSecret"));
        return gson.toJson(treeMap);
    }

    /**
     * 获取服务邮箱号配置内容
     *
     * @param params Map<String,String>
     * @return 邮箱配置内容
     */
    private String getEmailContext(Map<String,Object> params) {
        String emailUsername = (String)params.get("emailUsername");
        String emailPassword = (String)params.get("emailPassword");
        String emailHost = (String)params.get("emailHost");
        String port = (String)params.get("port");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("emailUsername", emailUsername);
        treeMap.put("emailPassword", emailPassword);
        treeMap.put("emailHost", emailHost);
        treeMap.put("port", port);
        return gson.toJson(treeMap);
    }

    /**
     * 获取网站基本信息配置内容
     *
     * @param params Map<String,String>
     * @return 基本信息配置内容
     */
    private String getInfoContext(Map<String,Object> params) {
        String title = (String)params.get("title");
        String appName = (String)params.get("appName");
        String tagline = (String)params.get("tagline");
        String company = (String)params.get("company");
        String author = (String)params.get("author");
        String keywords = (String)params.get("keywords");
        String description = (String)params.get("description");
        String email = (String)params.get("email");
        String phone = (String)params.get("phone");
        String workTime = (String)params.get("workTime");
        String copyright = (String)params.get("copyright");
        String copyright1 = (String)params.get("copyright1");
        String copyright2 = (String)params.get("copyright2");
        String copyright3 = (String)params.get("copyright3");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("title", title);
        treeMap.put("appName", appName);
        treeMap.put("tagline", tagline);
        treeMap.put("company", company);
        treeMap.put("author", author);
        treeMap.put("keywords", keywords);
        treeMap.put("description", description);
        treeMap.put("email", email);
        treeMap.put("phone", phone);
        treeMap.put("workTime", workTime);
        treeMap.put("copyright", copyright);
        treeMap.put("copyright1", copyright1);
        treeMap.put("copyright2", copyright2);
        treeMap.put("copyright3", copyright3);
        return gson.toJson(treeMap);
    }

    /**
     * 获取开关配置内容
     *
     * @param params Map<String,String>
     * @return 开关配置内容
     */
    private String getOnOffContext(Map<String,Object> params) {
        String paySwitch = (String)params.get("paySwitch");
        String loginSwitch = (String)params.get("loginSwitch");
        String integralSwitch = (String)params.get("integralSwitch");
        String experienceSwitch = (String)params.get("experienceSwitch");
        String mobileSwitch = (String)params.get("mobileSwitch");
        String subjectSwitch = (String)params.get("subjectSwitch");
        String liveBlendSwitch = (String)params.get("liveBlendSwitch");
//        String thirdLoginSwitch = (String)params.get("thirdLoginSwitch");
        String weiXinLoginSwitch = (String)params.get("weiXinLoginSwitch");
        String qqLoginSwitch = (String)params.get("qqLoginSwitch");
        String appDownloadCode = (String) params.get("appDownloadCode");
        String h5DownloadCode = (String) params.get("h5DownloadCode");
        String smallAppDownloadCode = (String) params.get("smallAppDownloadCode");
        String h5AppDownloadSwitch = (String) params.get("h5AppDownloadSwitch");
        String iosWithdraw = (String) params.get("iosWithdraw");
        String iosIncome = (String) params.get("iosIncome");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("paySwitch", this.getSwitch(paySwitch));
        treeMap.put("loginSwitch", this.getSwitch(loginSwitch));
        treeMap.put("integralSwitch", this.getSwitch(integralSwitch));
        treeMap.put("experienceSwitch", this.getSwitch(experienceSwitch));
        treeMap.put("mobileSwitch", this.getSwitch(mobileSwitch));
        treeMap.put("subjectSwitch", this.getSwitch(subjectSwitch));
        treeMap.put("liveBlendSwitch", this.getSwitch(liveBlendSwitch));
        treeMap.put("weiXinLoginSwitch", this.getSwitch(weiXinLoginSwitch));
        treeMap.put("qqLoginSwitch", this.getSwitch(qqLoginSwitch));
        treeMap.put("appDownloadCode",this.getSwitch(appDownloadCode));
        treeMap.put("h5DownloadCode",this.getSwitch(h5DownloadCode));
        treeMap.put("smallAppDownloadCode",this.getSwitch(smallAppDownloadCode));
        treeMap.put("h5AppDownloadSwitch",this.getSwitch(h5AppDownloadSwitch));
        treeMap.put("iosWithdraw",this.getSwitch(iosWithdraw));
        treeMap.put("iosIncome",this.getSwitch(iosIncome));
        return gson.toJson(treeMap);
    }

    private String getSwitch(String switchs) {
        if (switchs != null && switchs.equals("on")) {
            return "ON";
        }
        return "OFF";
    }

    /**
     * 获取知识Context内容
     *
     * @param params Map<String,String>
     * @return 配置内容
     */
    private String getSmsContext(Map<String,Object> params) {
        String AppKey = (String)params.get("AppKey");
        String appSecret = (String)params.get("appSecret");
        String appId = (String)params.get("appId");
        String serviceName = (String)params.get("serviceName");
        String sig = (String)params.get("sig");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("AppKey", AppKey);
        treeMap.put("appSecret", appSecret);
        treeMap.put("appId", appId);
        treeMap.put("serviceName", serviceName);
        treeMap.put("sig", sig);
        return gson.toJson(treeMap);
    }

    /**
     * 获取知识Context内容
     *
     * @param params Map<String,String>
     * @return 配置内容
     */
    private String getFreightContext(Map<String,Object> params) {
        String price = (String)params.get("price");
        if (StringUtils.isEmpty(price)) {
            price = "0";
        }
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("price", price);
        return gson.toJson(treeMap);
    }

    /**
     * 获取旁听分成比例配置内容
     *
     * @param params Map<String,String>
     * @return 配置内容
     */
    private String getAttentContext(Map<String,Object> params) {
        String sys = (String)params.get("sysTerrace");
        if(StringUtils.isEmpty(sys)){
            sys="0";
        }
        String user = (String)params.get("user");
        if(StringUtils.isEmpty(user)){
            user="0";
        }
        String teacher = (String)params.get("teacher");
        if(StringUtils.isEmpty(teacher)){
            teacher="0";
        }
        String refundSwitch = (String) params.get("refundSwitch");
        String refundTime = (String) params.get("refundTime");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("refundSwitch", getSwitch(refundSwitch));
        treeMap.put("refundTime", refundTime);
        treeMap.put("sysTerrace", sys);
        treeMap.put("user", user);
        treeMap.put("teacher", teacher);
        return gson.toJson(treeMap);
    }

    /**
     * 获取第三方统计代码配置内容
     *
     * @param params Map<String,String>
     * @return 配置内容
     */
    private String getCountCodeContext(Map<String,Object> params) {
        //第三方统计代码
        String code = (String)params.get("code");
        //第三方统计提供商(1百度统计,2腾讯分析,3CNZZ,4谷歌分析)
        String statisticsSwitch= (String)params.get("statisticsSwitch");
        //第三方统计对应配置参数(百度统计,腾讯分析,CNZZ,谷歌分析)
        String mateCode= (String)params.get("matecode");
        //第三方统计代码开关
        String statisticsOnOffSwitch= (String)params.get("statisticsOnOffSwitch");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("code", code);
        treeMap.put("mateCode", mateCode);
        treeMap.put("statisticsSwitch", statisticsSwitch);
        treeMap.put("statisticsOnOffSwitch",this.getSwitch(statisticsOnOffSwitch));
        return gson.toJson(treeMap);
    }

    /**
     * 获取微信配置内容
     *
     * @param params Map<String,String>
     * @return 配置内容
     */
    private String getWeiXinContext(Map<String,Object> params) {
        String appId = (String)params.get("appId");
        String secret = (String)params.get("secret");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("appId", appId);
        treeMap.put("secret", secret);
        return gson.toJson(treeMap);
    }

    /**
     * 获取QQ关联登录配置内容
     *
     * @param params
     * @return
     */
    private String getQQLoginContext(Map<String,Object> params) {
        String appId = (String)params.get("appId");
        String appKey = (String)params.get("appKey");
        String pcUrl = (String)params.get("pcUrl");
        String mobileUrl = (String)params.get("mobileUrl");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("appId", appId);
        treeMap.put("appKey", appKey);
        treeMap.put("pcUrl", pcUrl);
        treeMap.put("mobileUrl", mobileUrl);
        return gson.toJson(treeMap);
    }

    /**
     * 获取版本配置
     * @param params
     * @return
     */
    private String getVersionContext(Map<String,Object> params){
        TreeMap<String, String> treeMap = new TreeMap<>();
        String version = (String)params.get("version");
        treeMap.put("version",version);
        return gson.toJson(treeMap);
    }

    /**
     * 获取视频、直播、音频服务商配置
     * @param params 参数
     * @return 配置内容
     */
    public String getVLASProviderContext(Map<String,Object> params){
        TreeMap<String, String> treeMap = new TreeMap<>();
        String type = (String)params.get("type");
        String isK96keVideo = "ON";
        treeMap.put("type",type);
        //CC配置=============开始==
        String ccAppId = (String)params.get("ccAppId");
        treeMap.put("ccAppId",ccAppId);
        String ccAppKey = (String)params.get("ccAppKey");
        treeMap.put("ccAppKey",ccAppKey);
        String liveAppKey = (String)params.get("liveAppKey");
        treeMap.put("liveAppKey",liveAppKey);
        String encryption = (String)params.get("encryption");
        if("on".equals(encryption)){
            encryption = "ON";
        }else{
            encryption ="OFF";
        }
        treeMap.put("encryption",encryption);
        //CC配置=============结束==

        //3t配置===========开始==
        String account = (String)params.get("account");
        treeMap.put("account",account);
        String pwd = (String)params.get("pwd");
        treeMap.put("pwd",pwd);
        String sid = (String)params.get("sid");
        treeMap.put("sid",sid);
        String safeKey = (String)params.get("safeKey");
        treeMap.put("safeKey",safeKey);
        //3t配置===========结束==
        treeMap.put("isK96keVideo",isK96keVideo);
        return gson.toJson(treeMap);
    }

    /**
     * 获取微信关联登录配置内容
     *
     * @param params
     * @return
     */
    private String getWXLoginContext(Map<String,Object> params) {
        String appId = (String)params.get("appId");
        String appSecret = (String)params.get("appSecret");
        String pcOpenAppId = (String)params.get("pcOpenAppId");
        String pcOpenSecret = (String)params.get("pcOpenSecret");
        String adminOpenAppId = (String)params.get("adminOpenAppId");
        String adminOpenSecret = (String)params.get("adminOpenSecret");
        String mobileOpenAppId = (String)params.get("mobileOpenAppId");
        String mobileOpenSecret = (String)params.get("mobileOpenSecret");
        String pcUrl = (String)params.get("pcUrl");
        String mobileUrl = (String)params.get("mobileUrl");

        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("appId", appId);
        treeMap.put("appSecret", appSecret);
        treeMap.put("pcOpenAppId", pcOpenAppId);
        treeMap.put("pcOpenSecret", pcOpenSecret);
        treeMap.put("adminOpenAppId", adminOpenAppId);
        treeMap.put("adminOpenSecret", adminOpenSecret);
        treeMap.put("mobileOpenAppId", mobileOpenAppId);
        treeMap.put("mobileOpenSecret", mobileOpenSecret);
        treeMap.put("pcUrl", pcUrl);
        treeMap.put("mobileUrl", mobileUrl);
        return gson.toJson(treeMap);
    }


    /**
     * 获取微信关联登录配置内容
     *
     * @param params
     * @return
     */
    private String getServiceCourseContent(Map<String,Object> params) {
        String serviceCourseContent = (String)params.get("serviceCourseContent");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("serviceCourseContent", serviceCourseContent);
        return gson.toJson(treeMap);
    }

    /**
     * 获取问答自动退费配置
     * @param params
     * @return
     */
    private String getQaRefund(Map<String,Object> params){
        String refundTime = (String) params.get("refundTime");
        String refundSwitch = (String) params.get("refundSwitch");
        if(!refundSwitch.equals("on")){
            refundSwitch = "OFF";
        }else{
            refundSwitch = "ON";
        }
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("refundTime",refundTime);
        treeMap.put("refundSwitch",refundSwitch);
        return gson.toJson(treeMap);
    }


    /**
     * 获取微信关联登录配置内容
     *
     * @param params
     * @return
     */
    private String getLiveTimeContent(Map<String,Object> params) {
        String liveTime = (String)params.get("liveTime");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("liveTime", liveTime);
        return gson.toJson(treeMap);
    }


    /**
     * 获取微公众号二维码
     *
     * @param params
     * @return
     */
    private String getWechatServiceContent(Map<String,Object> params) {
        String url = (String)params.get("url");
        String serviceSwitch = (String)params.get("serviceSwitch");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("url", url);
        treeMap.put("serviceSwitch",  this.getSwitch(serviceSwitch));
        return gson.toJson(treeMap);
    }


    /**
     * 获取微信关联登录配置内容
     *
     * @param params
     * @return
     */
    private String getInitIdContent(Map<String,Object> params) {
        String liveTime = (String)params.get("initNum");
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("initNum", liveTime);
        return gson.toJson(treeMap);
    }
    /**
     * 把配置内容转成Json串
     */
    private String configContextToJsonStr(Map<String,Object> params) {
        if(ObjectUtils.isNotEmpty(params)){
            return gson.toJson(params);
        }
        return null;
    }
}
